package com.ruoyi.web.controller.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbPlanClassifyYear;
import com.ruoyi.wb.service.IWbPlanClassifyYearService;
import com.ruoyi.wb.service.IWbPlanService;
import com.ruoyi.wb.vo.WbPlanClassifyYearVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维保年度类目列Controller
 * 
 * @author ruoyi
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/system/year")
public class WbAppPlanClassifyYearController extends BaseController
{
    @Autowired
    private IWbPlanClassifyYearService wbPlanClassifyYearService;

    @Autowired
    private IWbPlanService iWbPlanService;

    /**
     * 查询维保年度类目列列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbPlanClassifyYear wbPlanClassifyYear)
    {
        startPage();
        List<WbPlanClassifyYear> list = wbPlanClassifyYearService.selectWbPlanClassifyYearList(wbPlanClassifyYear);
        return getDataTable(list);
    }

    /**
     * 查询维保年度类目列列表
     */
    @GetMapping("/allList")
    public TableDataInfo allList(WbPlanClassifyYear wbPlanClassifyYear)
    {
        startPage();
        List<WbPlanClassifyYearVo> list = wbPlanClassifyYearService.allList(wbPlanClassifyYear);
        return getDataTable(list);
    }
    /**
     * 查询维保年度类目列列表
     */
    @GetMapping("/allListByCreateBy")
    public TableDataInfo allList()
    {
        startPage();
        List<WbPlanClassifyYearVo> list = wbPlanClassifyYearService.allListByCreateBy();
        return getDataTable(list);
    }


    /**
     * 导出维保年度类目列列表
     */
    @Log(title = "维保年度类目列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbPlanClassifyYear wbPlanClassifyYear)
    {
        List<WbPlanClassifyYear> list = wbPlanClassifyYearService.selectWbPlanClassifyYearList(wbPlanClassifyYear);
        ExcelUtil<WbPlanClassifyYear> util = new ExcelUtil<WbPlanClassifyYear>(WbPlanClassifyYear.class);
        util.exportExcel(response, list, "维保年度类目列数据");
    }

    /**
     * 获取维保年度类目列详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbPlanClassifyYearService.selectWbPlanClassifyYearById(id));
    }

    /**
     * 新增维保年度类目列
     */
    @Log(title = "维保年度类目列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbPlanClassifyYear wbPlanClassifyYear)
    {
        return toAjax(wbPlanClassifyYearService.insertWbPlanClassifyYear(wbPlanClassifyYear));
    }

    /**
     * 修改维保年度类目列
     */
    @Log(title = "维保年度类目列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbPlanClassifyYear wbPlanClassifyYear)
    {
        return toAjax(wbPlanClassifyYearService.updateWbPlanClassifyYear(wbPlanClassifyYear));
    }


    /**
     * 删除维保年度类目列
     */
    @Log(title = "维保年度类目列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbPlanClassifyYearService.deleteWbPlanClassifyYearByIds(ids));
    }
    /**
     * 根据计划id查询年检目录包含目录内容
     */
     @ApiOperation("根据计划id查询年检目录包含目录内容")
     @GetMapping("/getCatalogueYearItemByPlanId")
    public TableDataInfo getCatalogueYearItemByPlanId(@RequestParam("planId") Long planId){
         List<WbPlanClassifyYearVo>  wbPlanClassifyYearVos=wbPlanClassifyYearService.getCatalogueYearItemByPlanId(planId);
//         WbPlan tempWbPlan = iWbPlanService.selectWbPlanById(planId);
//         try {
//             String xlsName = XlsCopyToPngUtil.copyXlsYear(wbPlanClassifyYearVos, tempWbPlan,false,new WbEntAuth());
//             String pngName = XlsCopyToPngUtil.xlsToPng(xlsName, PlanTypeEnums.YEAR.getType());
//             String pdfName = XlsCopyToPngUtil.xlsToPdf(xlsName,PlanTypeEnums.YEAR.getType());
//         } catch (Exception e) {
//             e.printStackTrace();
//         }

         return getDataTable(wbPlanClassifyYearVos);
     }
    /**
     * 批量新增维保年度类目列
     */
    @Log(title = "批量新增维保年度类目列", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestBody List<WbPlanClassifyYear> wbPlanClassifyYears)
    {
        return toAjax(wbPlanClassifyYearService.batchAdd(wbPlanClassifyYears));
    }


}
